Title Banner

Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Graphics /
Chapter 3 - Geometric Styles / Using Geometric Styles


Adding a Pattern to a Shape

To add a pattern to a shape, you must create a pattern structure. The pattern structure has four fields: the shape to use as the pattern, the pattern attributes, and a pair of vectors that define the grid over which QuickDraw GX places the pattern.

The sample function in Listing 3-19 creates a large rectangle shape patterned with small squares.

Listing 3-19 Patterning a shape

void CreatePatternedRectangle(void)
{
   gxShape  aRectangleShape, aSquarePattern;

   static gxRectangle rectangleGeometry = {ff(50), ff(50), 
                                           ff(250), ff(150)};

   static gxRectangle squareGeometry = {ff(0), ff(0), 
                                        ff(10), ff(10)};
            
   gxPatternRecord thePatternRecord;
   
   
   aRectangleShape = GXNewRectangle(&rectangleGeometry);

   aSquarePattern = GXNewRectangle(&squareGeometry);
      
   thePatternRecord.attributes = gxNoAttributes;
   thePatternRecord.pattern = aSquarePattern;
   thePatternRecord.u.x = ff(0);
   thePatternRecord.u.y = ff(20);
   thePatternRecord.v.x = ff(20);
   thePatternRecord.v.y = ff(0);

   GXSetShapePattern(aRectangleShape, &thePatternRecord);
   GXDisposeShape(aSquarePattern);
      
   GXDrawShape(aRectangleShape);
      
   GXDisposeShape(aRectangleShape);
}
Note
As with caps, joins, and dashes, QuickDraw GX copies only the geometric information of the pattern shape into the pattern property of the style object; it does not copy the entire pattern shape. For this reason, pattern shapes must be in primitive form. Once you have called GXSetShapePattern, you are free to change the original pattern shape without affecting the pattern of the patterned shape.
Notice that this sample function creates a square pattern shape 10 points high by 10 points wide. It places that square pattern on a rectangular grid 20 points high by 20 points wide, resulting in the shape shown in Figure 3-75.

Figure 3-75 A rectangle with a pattern

Although this example places the pattern shape on a rectangular grid, you are not limited to rectangular grids. The u and v fields of the pattern structure allow you to define a pair of vectors, so your pattern can be placed on any regular grid.

QuickDraw GX does not limit you to patterning filled shapes; you can pattern framed shapes as well. For example, if you change the previous example so that the rectangle shape is framed using the call

GXSetShapeFill(aRectangleShape, gxClosedFrameFill);
and has a thick pen width using the call

GXSetShapePen(aRectangleShape, ff(40));
the resulting function creates the shape shown in Figure 3-76.

Figure 3-76 A framed rectangle with a pattern

You can also pattern dashed shapes. For examples, see "Combining Caps, Joins, Dashes, and Patterns" on page 3-91.

The sections "The Pattern Structure" on page 3-106 and "Pattern Attributes" on page 3-107 describe the pattern record structure and pattern attributes in more detail, and the section "Getting and Setting Patterns" beginning on page 3-142 describes the functions you can use to manipulate patterns.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996




Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help